<%-- 
    Document   : pesquisarRecurso
    Created on : 19/10/2011, 11:41:44
    Author     : 0433101
--%>
<%@page import="Exceptions.PrivilegioInsuficienteException"%>
<%@page import="Model.Usuario"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file = "autenticacaoAdministrador.jsp"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Sistema Controle de Reservas</title>
        <script type="text/javascript">
            function validar(form){
                var id = form.id.value;
                var nome = form.nome.value;
                var idRecurso = Number(id);
                document.getElementById("idAlert").innerHTML = "";
                document.getElementById("nomeAlert").innerHTML = "";
                
                if(nome == "" && isNaN(idRecurso)){
                    document.getElementById("idAlert").innerHTML = "ID DEVE SER UM NÚMERO!";
                    form.id.focus();
                    return false;
                }
                else if(nome != "" && isNaN(idRecurso)){
                    form.id.value = "";
                    return true;
                }
                
                return true;
            }
        </script>
    </head>
    <body>
        <%            
            String destino = request.getParameter("destino");
            if(destino == null){
                destino = (String) session.getAttribute("destino");
                if(destino == null){
                    throw new Exception();
                }
            }
            session.setAttribute("destino", destino);
            
            String link = null;
            
            if(destino.equals("remover")){
                link = "removerRecurso.jsp";
            }
            else if(destino.equals("alterar")){
                link = "mostrarRecurso.jsp";
            }
            else{
                throw new Exception();
            } 
        %>
        <h1>Pesquisar Recurso:</h1>
        <div id="message">${erro}</div>
        <form name="formPesquisar" method="post" action="MainAccessServlet" onsubmit="return validar(this)" accept-charset="iso-8859-1,utf-8">
            <input type="hidden" value="<%=link%>" name="link"/>
            <input type="hidden" value="pesquisarRecurso" name="cmd"/>
            Pesquisar por Id:<input type="text" name="id"/><br>
            <label id="idAlert"></label><br>
            Pesquisar por Nome: <input type="text" name="nome"/><br>
            <label id="nomeAlert"></label><br>
            <input type="submit" value="Pesquisar"/><input type="reset" value="Limpar"/>
            <button type="button" onclick="location.href='menuAdministrador.jsp'">Voltar</button>
        </form>
    </body>
</html>
